#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  string s;
  cin >> s;
  int n = s.size(), K;
  cin >> K;
  s = " " + s;

  vector<vector<int>> dp(n + 2, vector<int>(n + 2));
  for (int l = n; l >= 1; l --) {
    dp[l][l] = 1;
    for (int r = l + 1; r <= n; r ++) {
      dp[l][r] = min(dp[l + 1][r], dp[l][r - 1]) + 1;
      for (int k = l; k < r; k ++) {
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
      }
      if (s[l] == 'o') {
        for (int k = l + 1; k <= r; k ++) {
          if (s[k] == 'f' && dp[l + 1][k - 1] == 0) {
            dp[l][r] = min(dp[l][r], max(0, dp[k + 1][r] - K));
          }
        }
      }
    }
  }
  cout << dp[1][n] << endl;
}